package br.org.etec.dotcao.dao.jpa;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import br.org.etec.dotcao.dao.NewsDao;
import br.org.etec.dotcao.model.News;

public class NewsDaoImpl extends JPAImpl<News> implements NewsDao{

	public NewsDaoImpl() {
		super(News.class);
	}
	
	@Override
	public List<News> all(String title, Date date) {
		TypedQuery<News> query = em.createNamedQuery("selectNews", News.class);
		query.setParameter("titleparam", title);		
		query.setParameter("date", date);		
		try {
			return query.getResultList();
		} catch (NoResultException e) {
			return Collections.emptyList();
		}
	}
	

}
